package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.EmployeeDAO;
import cn.edu.scau.cmi.hombio.dao.ExceptionTypeDAO;
import cn.edu.scau.cmi.hombio.dao.ExceptionTypeEmployeeDAO;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.ExceptionType;
import cn.edu.scau.cmi.hombio.domain.ExceptionTypeEmployee;

import cn.edu.scau.cmi.hombio.service.ExceptionTypeEmployeeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for ExceptionTypeEmployee entities
 * 
 */

@Controller("ExceptionTypeEmployeeRestController")

public class ExceptionTypeEmployeeRestController {

	/**
	 * DAO injected by Spring that manages Employee entities
	 * 
	 */
	@Autowired
	private EmployeeDAO employeeDAO;

	/**
	 * DAO injected by Spring that manages ExceptionType entities
	 * 
	 */
	@Autowired
	private ExceptionTypeDAO exceptionTypeDAO;

	/**
	 * DAO injected by Spring that manages ExceptionTypeEmployee entities
	 * 
	 */
	@Autowired
	private ExceptionTypeEmployeeDAO exceptionTypeEmployeeDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for ExceptionTypeEmployee entities
	 * 
	 */
	@Autowired
	private ExceptionTypeEmployeeService exceptionTypeEmployeeService;

	/**
	 * View an existing Employee entity
	 * 
	 */
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/employee/{employee_id}", method = RequestMethod.GET)
	@ResponseBody
	public Employee loadExceptionTypeEmployeeEmployee(@PathVariable Integer exceptiontypeemployee_id, @PathVariable Integer related_employee_id) {
		Employee employee = employeeDAO.findEmployeeByPrimaryKey(related_employee_id, -1, -1);

		return employee;
	}

	/**
	* Delete an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/employee/{employee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteExceptionTypeEmployeeEmployee(@PathVariable Integer exceptiontypeemployee_id, @PathVariable Integer related_employee_id) {
		exceptionTypeEmployeeService.deleteExceptionTypeEmployeeEmployee(exceptiontypeemployee_id, related_employee_id);
	}

	/**
	* Show all ExceptionTypeEmployee entities
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee", method = RequestMethod.GET)
	@ResponseBody
	public List<ExceptionTypeEmployee> listExceptionTypeEmployees() {
		return new java.util.ArrayList<ExceptionTypeEmployee>(exceptionTypeEmployeeService.loadExceptionTypeEmployees());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Save an existing ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/exceptionType", method = RequestMethod.PUT)
	@ResponseBody
	public ExceptionType saveExceptionTypeEmployeeExceptionType(@PathVariable Integer exceptiontypeemployee_id, @RequestBody ExceptionType exceptiontype) {
		exceptionTypeEmployeeService.saveExceptionTypeEmployeeExceptionType(exceptiontypeemployee_id, exceptiontype);
		return exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype.getId());
	}

	/**
	* Create a new ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/exceptionType", method = RequestMethod.POST)
	@ResponseBody
	public ExceptionType newExceptionTypeEmployeeExceptionType(@PathVariable Integer exceptiontypeemployee_id, @RequestBody ExceptionType exceptiontype) {
		exceptionTypeEmployeeService.saveExceptionTypeEmployeeExceptionType(exceptiontypeemployee_id, exceptiontype);
		return exceptionTypeDAO.findExceptionTypeByPrimaryKey(exceptiontype.getId());
	}

	/**
	* Create a new Employee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/employee", method = RequestMethod.POST)
	@ResponseBody
	public Employee newExceptionTypeEmployeeEmployee(@PathVariable Integer exceptiontypeemployee_id, @RequestBody Employee employee) {
		exceptionTypeEmployeeService.saveExceptionTypeEmployeeEmployee(exceptiontypeemployee_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Get Employee entity by ExceptionTypeEmployee
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/employee", method = RequestMethod.GET)
	@ResponseBody
	public Employee getExceptionTypeEmployeeEmployee(@PathVariable Integer exceptiontypeemployee_id) {
		return exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployee_id).getEmployee();
	}

	/**
	* Create a new ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee", method = RequestMethod.POST)
	@ResponseBody
	public ExceptionTypeEmployee newExceptionTypeEmployee(@RequestBody ExceptionTypeEmployee exceptiontypeemployee) {
		exceptionTypeEmployeeService.saveExceptionTypeEmployee(exceptiontypeemployee);
		return exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployee.getId());
	}

	/**
	* Get ExceptionType entity by ExceptionTypeEmployee
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/exceptionType", method = RequestMethod.GET)
	@ResponseBody
	public ExceptionType getExceptionTypeEmployeeExceptionType(@PathVariable Integer exceptiontypeemployee_id) {
		return exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployee_id).getExceptionType();
	}

	/**
	* Delete an existing ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/exceptionType/{exceptiontype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteExceptionTypeEmployeeExceptionType(@PathVariable Integer exceptiontypeemployee_id, @PathVariable Integer related_exceptiontype_id) {
		exceptionTypeEmployeeService.deleteExceptionTypeEmployeeExceptionType(exceptiontypeemployee_id, related_exceptiontype_id);
	}

	/**
	* Delete an existing ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteExceptionTypeEmployee(@PathVariable Integer exceptiontypeemployee_id) {
		ExceptionTypeEmployee exceptiontypeemployee = exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployee_id);
		exceptionTypeEmployeeService.deleteExceptionTypeEmployee(exceptiontypeemployee);
	}

	/**
	* View an existing ExceptionType entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/exceptionType/{exceptiontype_id}", method = RequestMethod.GET)
	@ResponseBody
	public ExceptionType loadExceptionTypeEmployeeExceptionType(@PathVariable Integer exceptiontypeemployee_id, @PathVariable Integer related_exceptiontype_id) {
		ExceptionType exceptiontype = exceptionTypeDAO.findExceptionTypeByPrimaryKey(related_exceptiontype_id, -1, -1);

		return exceptiontype;
	}

	/**
	* Save an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}/employee", method = RequestMethod.PUT)
	@ResponseBody
	public Employee saveExceptionTypeEmployeeEmployee(@PathVariable Integer exceptiontypeemployee_id, @RequestBody Employee employee) {
		exceptionTypeEmployeeService.saveExceptionTypeEmployeeEmployee(exceptiontypeemployee_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Save an existing ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee", method = RequestMethod.PUT)
	@ResponseBody
	public ExceptionTypeEmployee saveExceptionTypeEmployee(@RequestBody ExceptionTypeEmployee exceptiontypeemployee) {
		exceptionTypeEmployeeService.saveExceptionTypeEmployee(exceptiontypeemployee);
		return exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployee.getId());
	}

	/**
	* Select an existing ExceptionTypeEmployee entity
	* 
	*/
	@RequestMapping(value = "/ExceptionTypeEmployee/{exceptiontypeemployee_id}", method = RequestMethod.GET)
	@ResponseBody
	public ExceptionTypeEmployee loadExceptionTypeEmployee(@PathVariable Integer exceptiontypeemployee_id) {
		return exceptionTypeEmployeeDAO.findExceptionTypeEmployeeByPrimaryKey(exceptiontypeemployee_id);
	}
}